package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.common.utils.UserContext;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Delete;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author Aimer
 * @since 2025-11-04
 */
@RestController
@RequestMapping("/lessons")
@Api(tags = "学生课程表模块")
@RequiredArgsConstructor
public class LearningLessonController {
    private final ILearningLessonService iLearningLessonService;

    @ApiOperation("获取当前登录用户所学课程分页信息")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> getLearningLessonPage(PageQuery pageQuery) {
        return iLearningLessonService.getLearningLessonPage(pageQuery);
    }



    @ApiOperation(("删除课程表中学生的课程"))
    @DeleteMapping("/{courseId}")
    public void deleteLessonCourse(@PathVariable Long courseId){
        // 获取当前登录用户信息
        Long userId = UserContext.getUser();
        iLearningLessonService.deleteLesson(userId,courseId);
    }

    @ApiOperation("检查课程是否有效")
    @GetMapping("/{courseId}/valid")
    public Long isLessonValid(@PathVariable Long courseId){
        // 获取当前登录用户信息
        Long userId = UserContext.getUser();
        return iLearningLessonService.isLessonValid(userId,courseId);
    }

    @ApiOperation("查询用户课表中指定课程状态")
    @GetMapping("/{courseId}")
    public LearningLessonVO getUserLessonCourseStatus(@PathVariable Long courseId){
        // 获取当前登录用户信息
        Long userId = UserContext.getUser();
        return iLearningLessonService.getUserLessonCourseStatus(userId,courseId);
    }

    @ApiOperation("统计该课程的报名人数")
    @GetMapping("/{courseId}/count")
    public Integer getCourseNumber(@PathVariable Long courseId){
        return iLearningLessonService.getCourseNumber(courseId);
    }

    @ApiOperation("创建学习计划")
    @PostMapping("/plans")
    public void createCourseStudyPlans(@Valid @RequestBody LearningPlanDTO learningPlanDTO){
        iLearningLessonService.createCourseStudyPlans(learningPlanDTO.getCourseId(),learningPlanDTO.getFreq());
    }

    @ApiOperation("查询学习计划进度")
    @GetMapping("/plans")
    public LearningPlanPageVO queryMyPlans(PageQuery pageQuery){
        return iLearningLessonService.queryMyPlans(pageQuery);
    }

    @ApiOperation("查询正在学习的课程")
    @GetMapping("/now")
    public LearningLessonVO queryMyCurrentLesson(){
        return iLearningLessonService.queryMyCurrentLesson();
    }
}
